-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Don't let the authorization header be empty #1373
Conversation
@@ -177,7 +180,7 @@ export default class NpmRegistry extends Registry { | |||
} | |||
} | |||
|
|||
return ''; | |||
return undefined; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make this return an empty string please, we should ensure types are monomorphic if we can. An empty string will still evaluate the branch added above.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 My first change completely ignored flowtype and changed only this line. I didn't realize after having changed the code calling the method that the change there wasn't even necessary anymore.
It create problems with some servers like ProGet when used as a nuget cache. It's most likely the source of yarnpkg#825 and yarnpkg#1260
@@ -58,7 +58,10 @@ export default class NpmRegistry extends Registry { | |||
|
|||
const headers = {}; | |||
if (this.token || (alwaysAuth && requestUrl.startsWith(registry))) { | |||
headers.authorization = this.getAuth(pathname); | |||
const authorization = this.getAuth(pathname); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we consider adding test coverage here via a unit test?
Summary
This PR is aimed at solving problems with
@types
(And I guess other public scopes) that can be seen in #825 and #1260 where even with the latest version yarn fails to restore packages where npm succeed. The case is specific to enterprise caches as the yarn or npm default repositories aren't affected.In my case I had the problem and tested the resolution on ProGet ( http://inedo.com/proget ) configured with an NPM connector..
The issue is that
always-auth
is assumed for scoped packages, andalways-auth
forces the creation of anauthorization:
http header, even when no authentication can be found. The header is created empty in this case. As ProGet is an ASP.Net application and this platform consider an empty authorization header to be something that can never be met, it refuses the connection.This PR doesn't change the behavior of
always-auth
being assumed for scoped packages but it remove the empty header if no authentication can be found.Test plan
yarn
to restore packages in a previously non-working repository and checked that It worked, creating the lock file and was usable after. Testedyarn add
with a new packages in@types
I don't have access to a repository that require authentication for scoped packages but the change is minimal and doesn't affect any case where authentication was sent before so it shouldn't affect them (Also npm doesn't send the header in such cases)